package com.hjx.servlet;

import com.hjx.pojo.Order;
import com.hjx.service.orderService;
import com.sun.corba.se.impl.resolver.ORBDefaultInitRefResolverImpl;
import org.junit.Test;

import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

public class orderServlet extends HttpServlet {
    private orderService order=null;
    private List<Order> orderList=null;
    private ServletContext context=null;
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        order=new orderService();
        context=req.getServletContext();
//        暂且先设置总的页数为30条
        savetotalPageNum(context,10);

        String product_name=req.getParameter("product_name");
        String supplier=req.getParameter("supplier");
        String payStatus= req.getParameter("payStatus");

        System.out.println("pay:"+payStatus);
        System.out.println(product_name+" "+supplier+" "+payStatus);
        Object[] args=new Object[]{
                product_name,supplier,payStatus
        };
        try{
            orderList=order.getOrder(args);
            if (orderList!=null){
                System.out.println("orderList:");
                System.out.println(orderList);
//                将数据存入servletContext中
                context.setAttribute("order_condition",orderList);
//                将页面重定向到后台管理页面
                resp.sendRedirect("/super/Page/index.jsp");
            }else{
                System.out.println("order查询空");
            }

        }catch (Exception e){
            e.printStackTrace();
        }

    }

//    将页面的数量存入servletContext中，key=totalPageNum
    public void savetotalPageNum(ServletContext context,int totalPageNum){
        context.setAttribute("totalPageNum",totalPageNum);
    }




    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {

    }
}
